package com.lytxmd.boxtest.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.lytxmd.boxtest.R;
import com.lytxmd.boxtest.bean.DeviceInfo;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by zhangyinglong on 2017/5/19.
 */
public class EnergyListAdapter extends BaseAdapter{
    private List<DeviceInfo.PowerBean> datas = new ArrayList<>();

    @Override
    public int getCount() {
        return datas.size();
    }

    @Override
    public Object getItem(int i) {
        return datas.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View convertView, ViewGroup viewGroup) {
        ViewHolder vh;
        if (convertView == null){

            vh = new ViewHolder();
            convertView = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.energy_item,viewGroup,false);
            vh.energyDateTv = (TextView) convertView.findViewById(R.id.energy_date);
            vh.lightEnergyTv = (TextView) convertView.findViewById(R.id.light_energy_tv);
            vh.wordEnergyTv = (TextView) convertView.findViewById(R.id.word_energy_tv);
            convertView.setTag(vh);
        }else {
            vh = (ViewHolder) convertView.getTag();
        }
        vh.energyDateTv.setText(datas.get(i).getRecordTime());
        vh.lightEnergyTv.setText(""+datas.get(i).getPower());
        vh.wordEnergyTv.setText(""+datas.get(i).getPowerWord());
        return convertView;
    }
    class ViewHolder{
        private TextView energyDateTv, lightEnergyTv, wordEnergyTv;
    }
    public void setData(List<DeviceInfo.PowerBean> datas){
        this.datas = datas;
        notifyDataSetChanged();
    }
}
